-- EXEC SP_GET_REEL_QTY 1019

ALTER PROC SP_GET_REEL_QTY  ( @processStep_Id INT ) AS
BEGIN
	DECLARE @ass_processStep_id INT
	DECLARE @reel_qty VARCHAR(10)
	DECLARE @package VARCHAR(50)
	DECLARE @pin_count VARCHAR(50)
	
	SET @reel_qty = ''

	SELECT @ass_processStep_id = ProcessStep_ID FROM fn_get_process_flow_by_processStep_Id ( @processStep_Id ) WHERE PS_Type = 'Assembly' AND Process_Type_Name = 'Assembly'
	IF @ass_processStep_id IS NOT NULL AND @ass_processStep_id != -1
	BEGIN
		SELECT @package = Parameter_value FROM Process_parameter WHERE ProcessStep_ID = @ass_processStep_id AND Parameter_key = 'Package ID'
		SELECT @pin_count = Parameter_value FROM Process_parameter WHERE ProcessStep_ID = @ass_processStep_id AND Parameter_key = 'Pin'

		SELECT @reel_qty = Reel_Qty FROM REEL_QTY_Table WHERE Package = @package AND PIN_Count = CAST( @pin_count AS INT )
	END

	SELECT @reel_qty AS REEL_QTY
END